<template>
  <div style="height: 100%">
    <div @dblclick="reqdbleclick('2')" style="height: 100%">
      <div v-show="Options && Options.reqtabnoreqitems == '0'"
        style="position: fixed; z-index: 2007; top: 300px; padding-left: 100px; max-width: 400px">
        <span style="color: pink">{{ reqitemlist }}</span>
      </div>

      <vxe-table :data="tableDataApplyUp" @current-change="ApplyChange" @cell-dblclick="reqCellDblEvent" height="100%"
        highlight-current-row highlight-hover-row ref="xTableApplyUp" resizable highlight-hover-column border
        show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" size="mini" stripe width="800px">
        <vxe-table-column type="index" title=" " width="40" align="center"></vxe-table-column>
        <vxe-table-column :field="item.field" :title="item.title" :width="item.width" :key="item.field"
          v-for="item in tableColumnApplyUp"></vxe-table-column>
        <!-- <template v-slot:fix>
       
        </template> -->
      </vxe-table>
      <div class="fixbottom">
        <div style="float: left; padding-left: 10px; padding-bottom: 10px">
          <el-button style="background-color: #e6e6e6; color: black" @click="ShowCharge()"
            v-show="Options.showunprice == '1'">计费/退费</el-button>
          <el-button style="background-color: #e6e6e6; color: black" @click="reqdbleclick('3')"
            v-show="Options.hasOwnProperty('showreqitemmodifybtn') && Options.showreqitemmodifybtn == '1'">修改申请项目</el-button>
        </div>
        <div style="padding-right: 50px; background-color: #fff; text-align: right">
          <span style="color: blue; font-size: 8px; padding-right: 20px">项目数: {{ reqnum }}</span><span
            style="color: blue; font-size: 8px">金额: {{ reqamount }}</span>
        </div>

      </div>
    </div>

    <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false"
      :title="IsInputReqitemByPatNo ? '输入申请项目' : '修改申请项目'" width="800px" :visible.sync="dialogreqVisible"
      v-if="dialogreqVisible">
      <table>
        <tr>
          <td colspan="2">
            <div style="width: 760px">
              <vxe-table ref="xtablereqtop" :data="tableDataDialogreqSelect" border fit height="200px"
                header-align="center" highlight-current-row highlight-hover-row highlight-hover-column resizable
                show-header-overflow="tooltip" show-overflow="tooltip" size="mini" width="auto" stripe
                @cell-dblclick="cellDBLClickEvent($event, '1')"
                :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: true, activeMethod: activeMethod }">
                <vxe-table-column field="req_itemname" title="申请项目名称" width="160px" sortable></vxe-table-column>
                <vxe-table-column field="item_price" title="单价" width="60px" sortable></vxe-table-column>
                <vxe-table-column field="qty" title="数量" :edit-render="{ name: 'input', autoselect: true }" width="60px"
                  sortable>
                  <template v-slot:edit="{ row, rowIndex }">
                    <el-input type="number" v-model="row.qty" oninput="if(value < 1){ value = 1}"
                      @keyup.enter.native="ReqItemMove(row, 1, rowIndex, 'qty')"></el-input>
                  </template>
                  <template v-slot="{ row }">
                    <span>{{ row.qty }}</span>
                  </template>
                </vxe-table-column>
                <vxe-table-column field="req_itemcode" title="申请项目代码" width="100px" sortable></vxe-table-column>
                <vxe-table-column field="req_itemna" title="申请项目简称" width="160px" sortable></vxe-table-column>
              </vxe-table>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            快速查找: <el-input v-model="reqsearchinput" @input="reqsearch" style="width: 540px"></el-input>
            <a v-show="requesturl == 'LIS/LIS2/LIS212'">仅手工补费： <el-checkbox label="" v-model="payinback_flag"
                true-label="1" false-label="0" @change="reqdbleclick('3', 'payinback')"></el-checkbox></a>
          </td>
        </tr>
        <tr>
          <td>
            <div style="width: 600px">
              <vxe-table ref="xtablereqbottom" :data="tableDataDialogreq" border fit width="auto" stripe height="200px"
                header-align="center" size="mini" highlight-current-row highlight-hover-row highlight-hover-column
                resizable show-header-overflow="tooltip" show-overflow="tooltip"
                @cell-dblclick="cellDBLClickEvent($event, '2')" :loading="bShowPayLoading">
                <vxe-table-column field="req_itemname" title="申请项目名称" width="160px" sortable></vxe-table-column>
                <vxe-table-column field="item_price" title="单价" width="60px" sortable></vxe-table-column>
                <vxe-table-column field="qty" title="数量" width="60px" sortable></vxe-table-column>
                <vxe-table-column field="req_itemcode" title="申请项目代码" width="100px" sortable></vxe-table-column>
                <vxe-table-column field="req_itemna" title="申请项目简称" width="160px" sortable></vxe-table-column>
              </vxe-table>
            </div>
          </td>
          <td style="text-align: center">
            <div>
              <table style="width: 100%">
                <tr v-if="!IsInputReqitemByPatNo">
                  <td style="text-align: center">当前上机标本号</td>
                </tr>
                <tr v-if="!IsInputReqitemByPatNo">
                  <td style="text-align: center">{{ PatientInfo.reportid }}</td>
                </tr>
                <tr v-if="!IsInputReqitemByPatNo">
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td style="text-align: center">
                    <el-button @click="ReqChangeSubmit">确 定</el-button>
                  </td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td style="text-align: center">
                    <el-button @click="dialogreqVisible = false">取 消</el-button>
                  </td>
                </tr>
              </table>
            </div>
          </td>
        </tr>
      </table>
    </el-dialog>

    <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="申请单计价/退费(按项目)" width="800px"
      :visible.sync="dialogreqchargeVisible" v-if="dialogreqchargeVisible">
      <div style="height: 250px">
        <vxe-table :data="tableDatareqcharge" height="100%" highlight-current-row highlight-hover-row
          ref="xTableApplyCharge" resizable highlight-hover-column border show-header-overflow="tooltip"
          show-overflow="tooltip" header-align="center" size="mini" stripe width="800px">
          <vxe-table-column field="pat_typename" title="病人来源" width="60px" align="center"></vxe-table-column>
          <vxe-table-column field="pat_no" title="病历号" width="80px"></vxe-table-column>
          <vxe-table-column field="pat_name" title="姓名" width="50px" align="center"></vxe-table-column>
          <vxe-table-column field="charge_flagname" title="计价标志" width="50px"></vxe-table-column>
          <vxe-table-column type="selection" title="" width="50px" align="center"></vxe-table-column>
          <vxe-table-column field="req_itemname" title="申请项目名称" width="120px"></vxe-table-column>
          <vxe-table-column field="item_price" title="单价" width="50px" align="right"
            header-align="center"></vxe-table-column>
          <vxe-table-column field="qty" title="数量" width="50px" align="right" header-align="center"></vxe-table-column>
          <vxe-table-column field="seq" title="序号" width="50px" align="right" header-align="center"></vxe-table-column>
          <vxe-table-column field="chargefailmsg" title="计价信息/失败原因" width="140px"></vxe-table-column>
          <vxe-table-column field="barcode" title="条码号" width="80px"></vxe-table-column>
          <vxe-table-column field="req_groupna" title="分单类别" width="50px"></vxe-table-column>
          <vxe-table-column field="recieve_dt" title="接收时间" width="120px" align="center"></vxe-table-column>
          <vxe-table-column field="recieve_username" title="接收人" width="100px" align="center"></vxe-table-column>
          <vxe-table-column field="emer_flagname" title="加急" width="50px"></vxe-table-column>
          <vxe-table-column field="req_statname" title="状态" width="50px"></vxe-table-column>
          <vxe-table-column field="req_deptname" title="申请科室" width="50px"></vxe-table-column>
          <!-- <vxe-table-column field="barcode" title="上机标本号" width="50px"></vxe-table-column> -->
          <vxe-table-column field="req_docname" title="申请医生" width="50px"></vxe-table-column>
          <vxe-table-column field="req_bedno" title="床号" width="50px"></vxe-table-column>
          <vxe-table-column field="specimen_name" title="标本类型" width="50px"></vxe-table-column>
          <vxe-table-column field="his_refcol1" title="HIS表相关字段1" width="100px"></vxe-table-column>
          <vxe-table-column field="his_refcol2" title="HIS表相关字段2" width="100px"></vxe-table-column>
          <vxe-table-column field="his_refcol3" title="HIS表相关字段3" width="100px"></vxe-table-column>
          <vxe-table-column field="req_itemcode" title="项目代码" width="100px"></vxe-table-column>
          <vxe-table-column field="reportid" title="报告ID" width="50px"></vxe-table-column>
        </vxe-table>
      </div>
      <div style="margin-top: 5px; width: 100%; text-align: right">
        <el-button @click="ChargesApply(1)">计费</el-button>
        <el-button @click="QueryCharges()">刷新</el-button>
        <el-button @click="ChargesApply(2)">退费</el-button>
        <el-button @click="dialogreqchargeVisible = false">退出</el-button>
      </div>
    </el-dialog>

    <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="申请项目报告项目对照" width="1000px"
      :visible.sync="reqtorptVisible" v-if="reqtorptVisible">
      <div style="height: 540px">
        <rm-layout-right splitcolor="#ffffff" :splitwidth="3" :fixsize="500" :minfixsize="200" ref="layoutright">
          <div>
            <div style="height: 30px">
              当前申请项目: <span style="color: blue; font-weight: bold">{{ nowreqitemname }}</span>
            </div>
            <vxe-table :data="tableDataReq" @cell-dblclick="reqtorptDblEvent($event, '1')" height="500px"
              highlight-current-row highlight-hover-row ref="reprpttable" resizable highlight-hover-column border
              show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" size="mini" stripe
              width="480px">
              <vxe-table-column field="rpt_itemname" sortable title="对应报告项目" width="120"></vxe-table-column>
              <vxe-table-column field="seq" sortable title="序号" width="40" align="center"></vxe-table-column>
              <vxe-table-column align="center" field="optional" sortable title="可选" width="40">
                <template v-slot="{ row }">
                  <el-checkbox v-model="row.optional" true-label="1" false-label="0" disabled></el-checkbox>
                </template>
              </vxe-table-column>
              <vxe-table-column field="defaultvalue" sortable title="默认值" width="120"></vxe-table-column>
              <vxe-table-column field="externalcode1" sortable title="外部代码1" width="120"></vxe-table-column>
              <vxe-table-column field="externalcode2" sortable title="外部代码2" width="120"></vxe-table-column>
              <vxe-table-column field="externalcode3" sortable title="外部代码3" width="120"></vxe-table-column>

              <!-- <vxe-table-column field="req_itemcode" sortable title="申请项目代码" width="80"></vxe-table-column> -->
              <vxe-table-column field="rpt_itemcode" sortable title="报告项目代码" width="80"></vxe-table-column>
              <template v-slot:fix>
                <div style="width: 100%; text-align: right; background-color: white">
                  <span style="color: blue; font-size: 8px; padding-right: 20px">项目数: {{ tableDataReq.length }}</span>
                </div>
              </template>
            </vxe-table>
          </div>
          <template v-slot:fix>
            <div>
              <div style="height: 30px">
                <el-input v-model="reqrptselect" @change="reqFilter" @keyup.enter.native="reqFilter(reqrptselect)"
                  placeholder="输入信息后回车过滤报告项目"></el-input>
              </div>
              <vxe-table :data="tableDataRpt" @cell-dblclick="reqtorptDblEvent($event, '2')" height="500px"
                highlight-current-row highlight-hover-row ref="rptalltable" resizable highlight-hover-column border
                show-header-overflow="tooltip" show-overflow="tooltip" header-align="center" size="mini" stripe
                width="480px">
                <vxe-table-column field="itemcode_en" sortable title="英文缩写" width="70"></vxe-table-column>
                <vxe-table-column field="rpt_itemname" sortable title="报告项目名称" width="110"></vxe-table-column>
                <vxe-table-column field="itemclassname" sortable title="项目归类" width="70"></vxe-table-column>
                <vxe-table-column field="instrclass" sortable title="仪器类别" width="70"></vxe-table-column>
                <vxe-table-column field="rpt_itemcode" sortable title="报告项目代码" width="90"></vxe-table-column>
                <vxe-table-column field="seq" sortable title="打印序号" width="70"></vxe-table-column>
              </vxe-table>
            </div>
          </template>
        </rm-layout-right>
      </div>
      <div style="text-align: right">
        <el-button @click="SaveRptVsReq()">确定</el-button>
        <el-button @click="reqtorptVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import XEUtils from "xe-utils";
export default {
  props: {
    PatientInfo: { type: Object },
    specno: { type: String },
    rptunitid: { type: Number },
    Options: { type: Object },
    payinback_flag: { type: String, default: "0" },
    requesturl: {
      type: String,
      default: "LIS/LIS3/LIS310",
      require: false,
    },
    prono: {
      type: String,
      default: "",
      require: false,
    },
    shift: false,

    tableDataNowRpt: [], //当前申请项目对照的报告项目
    tableDataAllRpt: [], //未对照的报告项目
  },
  data() {
    return {
      tableDataDialogreqSelect: [], //已选中申请项目
      tableDataDialogreqAll: [],
      tableDataDialogreq: [],
      dialogreqVisible: false,
      dialogreqtype: "",
      reqsearchinput: "", //申请项目过滤字段
      //申请tab
      tableDataApplyUp: [], //申请TAB页上部数据
      tableColumnApplyUp: [], //申请TAB页上部数据列
      reqitemlist: "", //申请项目显示文字
      reqamount: 0, //申请项目显示金额
      reqnum: 0, //申请项目显示数量
      //申请单计价
      dialogreqchargeVisible: false,
      tableDatareqcharge: [],

      reqtorptVisible: false, //申请项目报告项目对照弹窗显示标志
      tableDataReq: [],
      tableDataRpt: [],
      tableDataRptAll: [],
      nowreqitem: "",
      nowreqitemname: "",
      reqrptselect: "",
      bShowPayLoading: false,
      IsInputReqitemByPatNo: false,//是否根据病人号手工输入申请项目
      execingflag: false,
    };
  },
  methods: {
    //申请tab双击弹窗双击事件
    cellDBLClickEvent({ row, rowIndex, column }, e) {
      if (this.dialogreqtype == "1") {
        if (e == "1") {
          this.tableDataDialogreqSelect = this.tableDataDialogreqSelect.filter((item) => item.req_itemcode != row.req_itemcode);
        } else {
          if (this.tableDataDialogreqSelect.filter((item) => item.req_itemcode == row.req_itemcode).length == 0) {
            row.lab_add = "1";
            row.newadd = true; // 增加当前新增判断标志，用于修改当前新增的数量，否则不可以修改
            this.tableDataDialogreqSelect.push(row);
          }
        }
      } else {
        if (e == "1" && row.lab_add == "1") {
          if (column.property != "qty") {
            this.$refs.xtablereqtop.remove(row);
          }
        } else if (e == "1" && !row.lab_add) {
          if (this.Options.allowdelnolabadditem != "1") this.$alert("本申请项目不是实验室新增,不能删除!");
          else this.$refs.xtablereqtop.remove(row);
        } else {
          var ishave = this.$refs.xtablereqtop.tableFullData.find((item) => item.req_itemcode == row.req_itemcode);

          if (this.Options.allowrepeataddreqitem == "1" && ishave) {
            this.$confirm("当前项目已存在，你是否要重复插入！", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {
                // row.lab_add = "1";
                row.newadd = true;
                this.$delete(row, '_XID');
                this.$refs.xtablereqtop.insertAt(JSON.parse(JSON.stringify(row)), -1);
                //this.tableDataDialogreqSelect.push(row);
              })
              .catch(() => { });
          } else if (!ishave) {
            //row.lab_add = "1";
            row.newadd = true; // 增加当前新增判断标志，用于修改当前新增的数量，否则不可以修改
            this.$delete(row, '_XID');
            this.$refs.xtablereqtop.insertAt(JSON.parse(JSON.stringify(row)), -1);
          }
        }
      }
    },

    ReqChangeSubmit() {
      if (this.execingflag) {
        return;
      }
      this.execingflag = true;
      try {
        var removerow = this.$refs.xtablereqtop.getRecordset().removeRecords;
        var insertrow = this.$refs.xtablereqtop.getRecordset().insertRecords;
        var allrow = this.tableDataDialogreqSelect;
        if (this.dialogreqtype == "1") {
          let str = "";
          let reqitemcodes = [];
          if (allrow.length > 0) {
            str += allrow[0].req_itemna ? allrow[0].req_itemna : allrow[0].req_itemname;
            reqitemcodes.push(allrow[0].req_itemcode);
            for (let i = 1; i < allrow.length; i++) {
              let name = "," + (allrow[i].req_itemna ? allrow[i].req_itemna : allrow[i].req_itemname);
              str += name;
              reqitemcodes.push(allrow[i].req_itemcode);
            }
          }
          this.PatientInfo.req_reason = str;
          this.$tool
            .request({
              url: this.requesturl,
              method: "post",
              data: {
                action: "getrptitembyreqitem",
                sampleno: this.specno,
                reportid: this.PatientInfo.reportid,
                rptunitid: this.rptunitid,
                req_itemcodes: reqitemcodes,
              },
            })
            .then((res) => {
              if (res.Data) {
                this.$emit("reqtorptitem", res.Data);
                // for (let i = 0; i < res.Data.length; i++) {
                //     if (this.$refs.rmlabresult.$refs.xTableResult.tableFullData.filter((item) => item.rpt_itemcode == res.Data[i].rpt_itemcode) == 0) {
                //         this.$refs.rmlabresult.$refs.xTableResult.insertAt(res.Data[i], -1);
                //     }
                //     this.dialogreqVisible = false;
                // }
                if (res.specimen && res.specimen.length > 0) {
                  if (this.PatientInfo.specimen_code == "") {
                    this.PatientInfo.specimen_code = res.specimen[0].specimen_code;
                    this.PatientInfo.specimen_codename = res.specimen[0].specimen_name;
                  }
                }
                this.execingflag = false;
              }
            });
        } else if (this.IsInputReqitemByPatNo) {
          this.$tool
            .request({
              url: this.requesturl,
              method: "post",
              data: {
                action: "savepopaddreqitem",
                patinfo: this.PatientInfo,
                reportid: this.PatientInfo.reportid,
                rptunitid: this.rptunitid,
                sampleno: this.specno,
                pat_no: this.PatientInfo.pat_no,
                pat_name: this.PatientInfo.pat_name,
                insertstr: insertrow,
              },
            })
            .then((res) => {
              console.log(res);
              if (res.flag == 1) {
                this.$message({
                  type: "success",
                  message: "保存成功",
                });
                this.PatientInfo.barcode = res.barcode;
                this.$nextTick(() => {
                  this.$emit("reqtorptitem");
                  this.tableDataApplyUp = JSON.parse(JSON.stringify(this.$refs.xtablereqtop.tableFullData));
                  this.$emit("addreqitembypatno");
                  this.dialogreqVisible = false;
                });
                this.execingflag = false;
              } else {
                this.$alert(res.msg, "错误", {
                  confirmButtonText: "确定",
                });
                this.execingflag = false;
              }
            });
        } else {
          this.$tool
            .request({
              url: this.requesturl,
              method: "post",
              data: {
                action: "savepopmodifyreqitem",
                barcode: this.PatientInfo.barcode,
                reportid: this.PatientInfo.reportid,
                rptunitid: this.rptunitid,
                sampleno: this.specno,
                insertstr: insertrow,
                removestr: removerow,
                prono: this.prono,
              },
            })
            .then((res) => {
              if (res.flag == 1) {
                this.$message({
                  type: "success",
                  message: "保存成功",
                });
                this.$nextTick(() => {
                  this.$emit("reqtorptitem");
                  this.tableDataApplyUp = JSON.parse(JSON.stringify(this.$refs.xtablereqtop.tableFullData));
                  this.dialogreqVisible = false;
                });
                this.execingflag = false;
              } else {
                this.$alert(res.msg, "错误", {
                  confirmButtonText: "确定",
                });
                this.execingflag = false;
              }
            });
        }
      } catch (e) {
        this.execingflag = false;
      }
    },

    //申请tab表格双击开窗事件
    reqdbleclick(type, kindno) {
      console.log("shift1", this.shift);
      if (this.shift) return;
      this.dialogreqtype = type;
      this.IsInputReqitemByPatNo = false;
      if (type == "3") this.dialogreqtype = "2";
      if (this.Options.hasOwnProperty("showreqitemmodifybtn") && type != "3") return;
      var kindno = "0";
      if (type == "1") {
        if (this.Options.modifypurposedbclick == "1" && !this.UpdateJudge()) kindno = "1";
      } else {
        if (this.prono.indexOf("BAC") > -1) {
          if (this.Options.showreqitemmodifybtn == "1" && this.PatientInfo.barcode) kindno = "1";
        } else {
          if ((this.Options.dbclickmodifyreqitem == "1" || this.Options.inputitembypatno == "1") && !this.UpdateJudge()) kindno = "1";
        }
      }
      console.log("w", this.PatientInfo.barcode, kindno);
      if (type == "1") {
        if (kindno == "1") {
          this.tableDataDialogreqSelect = [];
          this.$tool
            .request({
              url: this.requesturl,
              method: "post",
              data: {
                action: "getrptunitreqitem",
                sampleno: this.specno,
                rptunitid: this.rptunitid,
              },
            })
            .then((res) => {
              this.tableDataDialogreqAll = XEUtils.clone(res.data, true);
              this.tableDataDialogreq = res.data;
            });
          this.dialogreqVisible = true;
        }
      } else {
        if (kindno == "1") {
          //无检验申请信息等也开窗手工输入申请项目&无pat_no(有病人姓名)也可以开窗输入申请项目
          if (this.Options.inputitembypatno == "1" && this.tableDataApplyUp.length == 0
            && !this.PatientInfo.barcode && ((!this.PatientInfo.pat_no && this.PatientInfo.pat_name
              && this.Options.nopatnoalsoinputitem == "1") || this.PatientInfo.pat_no)) {
            this.IsInputReqitemByPatNo = true;
            this.tableDataDialogreqSelect = [];
            this.$tool
              .request({
                url: this.requesturl,
                method: "post",
                data: {
                  action: "getrptunitreqitem",
                  sampleno: this.specno,
                  rptunitid: this.rptunitid,
                },
              })
              .then((res) => {
                this.tableDataDialogreqAll = XEUtils.clone(res.data, true);
                this.tableDataDialogreq = res.data;
              });
            this.dialogreqVisible = true;
          } else if (this.Options.dbclickmodifyreqitem == "1" && this.PatientInfo.barcode) {
            this.tableDataDialogreqSelect = [];
            this.tableDataDialogreqAll = [];
            this.tableDataDialogreq = [];
            this.bShowPayLoading = true;
            this.$tool
              .request({
                url: this.requesturl,
                method: "post",
                data: {
                  action: "popmodifyreqitem",
                  barcode: this.PatientInfo.barcode,
                  reportid: this.PatientInfo.reportid,
                  rptunitid: this.rptunitid,
                  payinback_flag: this.payinback_flag,
                },
              })
              .then((res) => {
                this.bShowPayLoading = false;
                this.tableDataDialogreqSelect = res.top;
                this.tableDataDialogreqAll = XEUtils.clone(res.bottom, true);
                this.tableDataDialogreq = res.bottom;
              });
            // this.bShowPayLoading = false;
            this.dialogreqVisible = true;
          }

        }
      }
    },
    QueryCharges() {
      this.$tool
        .request({
          url: this.requesturl,
          method: "post",
          data: {
            action: "reqdetailchargesearch",
            barcode: this.PatientInfo.barcode,
          },
        })
        .then((res) => {
          if (res.hasOwnProperty("flag") && res.flag == "1") {
            this.tableDatareqcharge = res.Data;
          }
        });
    },
    ChargesApply(type) {
      if (this.execingflag) {
        return;
      }
      this.execingflag = true;
      var datas = this.$refs.xTableApplyCharge.getSelectRecords();
      this.$tool
        .request({
          url: this.requesturl,
          method: "post",
          data: {
            action: "reqchargeoruncharge",
            barcode: this.PatientInfo.barcode,
            reportid: this.PatientInfo.reportid,
            sampleno: this.specno,
            selectstr: datas,
            chargetype: type,
            prono: this.prono,
          },
        })
        .then((res) => {
          if (res.hasOwnProperty("flag") && res.flag == "1") {
            var msg = "计价";
            if (type == "2") msg = "退费";
            this.$message.success(msg + "成功");
            this.QueryCharges();
          } else {
            this.$alert(res.msg, "提示");
          }
          this.execingflag = false;
        })
        .catch(() => {
          this.execingflag = false;
        });
    },
    DealApplyData(res) {
      // console.log(res);
      this.tableDataApplyUp = res.Data;
      if (res.Cols.length > 0) this.tableColumnApplyUp = res.Cols;
      this.reqitemlist = "";
      this.reqamount = 0;
      this.reqnum = res.Data.length;
      if (res.Data.length > 0) {
        for (let i = 0; i < res.Data.length; i++) {
          if (i < res.Data.length - 1) this.reqitemlist += res.Data[i].req_itemname + ",";
          else this.reqitemlist += res.Data[i].req_itemname;
          let loopamount = 0;
          if (res.Data[i].amount && res.Data[i].amount != "") loopamount = parseFloat(res.Data[i].amount);
          this.reqamount = parseFloat(this.reqamount) + loopamount;
        }
      }
    },
    ApplyChange({ row }) {
      this.$emit("reqchange", row.req_itemcode);
    },
    UpdateJudge() {
      if (this.PatientInfo.rechkflag == "9" || (this.Options.onlymodifymyreport == "1" && this.$tool.getSession(this.$tool.loginuserno) != this.PatientInfo.report_user) || (this.PatientInfo.barcode && this.PatientInfo.barcode.indexOf("-退") > -1)) {
        return true;
      } else {
        return false;
      }
    },
    ShowCharge() {
      this.dialogreqchargeVisible = true;
      this.QueryCharges();
      //this.tableDatareqcharge = XEUtils.clone(this.tableDataApplyUp, true);
    },
    reqsearch(val) {
      if (val) {
        this.tableDataDialogreq = this.tableDataDialogreqAll.filter((item) => item.req_itemcode.toUpperCase().indexOf(val.toUpperCase()) > -1 || item.req_itemname.toUpperCase().indexOf(val.toUpperCase()) > -1 || (item.req_itemna ? item.req_itemna.toUpperCase().indexOf(val.toUpperCase()) > -1 : false) || (item.inputcode ? item.inputcode.toUpperCase().indexOf(val.toUpperCase()) > -1 : false));
      } else {
        this.tableDataDialogreq = XEUtils.clone(this.tableDataDialogreqAll, true);
      }
    },
    activeMethod({ row, column }) {
      let editfield = ["qty"];
      if (editfield.includes(column.property)) {
        if (this.Options.reqitemwithnumflag == "1" && row.lab_add == "1" && row.newadd) {
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    },
    reqCellDblEvent({ row }) {
      if (this.shift) {
        this.nowreqitem = row.req_itemcode;
        this.nowreqitemname = row.req_itemname;
        this.QueryRptVs(row);
      }
    },
    QueryRptVs(row) {
      this.$tool
        .request({
          url: this.requesturl,
          method: "post",
          data: {
            action: "queryrptfromreq",
            req_itemcode: row.req_itemcode,
            rptunitid: this.rptunitid,
          },
        })
        .then((res) => {
          if (res.errcode == "1") {
            this.tableDataReq = res.RData.Data;
            this.tableDataRptAll = res.rptdt;
            this.reqrptselect = "";
            this.reqFilter(this.reqrptselect);
            this.reqtorptVisible = true;
          } else {
            this.$alert(res.errmsg, "提示");
          }
        });
    },
    SaveRptVsReq() {
      var urec = this.$refs.reprpttable.getRecordset();
      this.$tool
        .request({
          url: this.requesturl,
          method: "post",
          data: {
            action: "saverptvsreq",
            reqitemcode: this.nowreqitem,
            urec: urec,
          },
        })
        .then((res) => {
          if (res.errcode == "1") {
            this.reqtorptVisible = false;
            this.$message.success("保存成功!", "提示");
          } else {
            this.$alert(res.errmsg, "提示");
          }
        });
    },
    reqFilter(val) {
      var data = this.tableDataReq;
      if (this.$refs.reprpttable) data = this.$refs.reprpttable.tableFullData;
      if (val) this.tableDataRpt = this.tableDataRptAll.filter((item) => ((item.itemcode_en && item.itemcode_en.toUpperCase().indexOf(val.toUpperCase()) > -1) || (item.rpt_itemname && item.rpt_itemname.toUpperCase().indexOf(val.toUpperCase()) > -1) || (item.itemclassname && item.itemclassname.toUpperCase().indexOf(val.toUpperCase()) > -1) || (item.instrclass && item.instrclass.toUpperCase().indexOf(val.toUpperCase()) > -1) || (item.rpt_itemcode && item.rpt_itemcode.toUpperCase().indexOf(val.toUpperCase()) > -1)) && !data.find((tableitem) => tableitem.rpt_itemcode == item.rpt_itemcode));
      else this.tableDataRpt = this.tableDataRptAll.filter((item) => !data.find((tableitem) => tableitem.rpt_itemcode == item.rpt_itemcode));
    },
    reqtorptDblEvent({ row }, type) {
      //type=1 从左边删除报告项目, =2从右往左添加项目
      if (type == "1") {
        this.$refs.reprpttable.remove(row);
      } else {
        var seq = 0;
        if (this.$refs.reprpttable.tableFullData.length > 0) seq = this.$refs.reprpttable.tableFullData[this.$refs.reprpttable.tableFullData.length - 1].seq;
        var eseq = seq - 0 + 10;
        row.seq = eseq;
        this.$refs.reprpttable.insertAt(row, -1);
        this.$refs.reprpttable.scrollToRow(row);
        this.$refs.reprpttable.setCurrentRow(row);
      }
      this.reqFilter(this.reqrptselect);
    },
    ReqItemMove(row, type, index, coltype) {
      if (index < this.$refs.xtablereqtop.tableFullData.length - 1) {
        var row = this.$refs.xtablereqtop.tableFullData[index + 1];
        this.$refs.xtablereqtop.setCurrentRow(row);
        if (coltype == "qty") {
          this.linkshow = true;
          this.$refs.xtablereqtop.setActiveCell(row, "qty");
        }
      }
    },

  },
};
</script>

<style>
.fixbottom {
  position: absolute;
  left: 0px;
  bottom: 3%;
  z-index: 1;
  overflow: hidden;
  width: 100%;
}
</style>